1 /*
2 * PreferencesNode
3 *
4 * $RCSfile: PreferencesNode.java,v $
5 * $Revision: 1.3 $
6 * $Date: 2004/01/10 20:10:46 $
7 * $Source: /cvsroot/jpui/jpui/src/PreferencesNode.java,v $
8 *
9 * JPUI - Java Preferences User Interface
10 * Copyright (C) 2003
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 * more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
24 * Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Author: macksold@users.sourceforge.net
27 */
28
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.OutputStream;
32 import java.util.prefs.BackingStoreException;
33 import java.util.prefs.InvalidPreferencesFormatException;
34 import java.util.prefs.NodeChangeListener;
35 import java.util.prefs.PreferenceChangeListener;
36 import java.util.prefs.Preferences;
37
38 /***
39 * Subclasses Preferences and overrides toString to
40 * cleanup the node names that are displayed in
41 * the JTree
42 */
43 public class PreferencesNode extends Preferences {
44 private Preferences moPref = null;
45
46 /***
47 * private ctor
48 */
49 private PreferencesNode() {
50 }
51
52 /***
53 * Public ctor
54 * @param oPref node to delegate to
55 */
56 public PreferencesNode(Preferences oPref) {
57 moPref = oPref;
58 }
59
60 /***
61 * Access for the deligate java.util.prefs.Preferences object
62 * Used by java.lang.Object.equals
63 * @return java.util.prefs.Preferences
64 */
65 protected Preferences getPreferences() {
66 return moPref;
67 }
68
69 /***
70 * @see java.util.prefs.Preferences.parent
71 * @return java.util.prefs.Preferences
72 */
73 public Preferences parent() {
74 if(moPref.parent() == null) {
75 return null;
76 }
77 else {
78 return new PreferencesNode(moPref.parent());
79 }
80 }
81
82 /***
83 * Returns a friendly string name for a node, suitable
84 * for display in the JTree
85 *
86 * @see java.lang.Object#toString()
87 */
88 public String toString() {
89 if(moPref.parent() == null) {
90 if(moPref.isUserNode() == true) {
91 return "User";
92 }
93 else {
94 return "System";
95 }
96 }
97 else {
98 return moPref.name();
99 }
100 }
101
102 /***
103 * Custom equals impl to compare the wrapped preferences objects
104 *
105 * @see java.lang.Object#equals(java.lang.Object)
106 */
107 public boolean equals(Object obj) {
108 return moPref.equals(((PreferencesNode)obj).getPreferences());
109 }
110
111 /* (non-Javadoc)
112 * @see java.util.prefs.Preferences#importPreferences(java.io.InputStream)
113 */
114 public static void importPreferences(InputStream is)
115 throws IOException, InvalidPreferencesFormatException {
116 Preferences.importPreferences(is);
117 }
118
119 /* (non-Javadoc)
120 * @see java.util.prefs.Preferences#systemNodeForPackage(java.lang.Class)
121 */
122 public static Preferences systemNodeForPackage(Class c) {
123 return Preferences.systemNodeForPackage(c);
124 }
125
126 /* (non-Javadoc)
127 * @see java.util.prefs.Preferences#systemRoot()
128 */
129 public static Preferences systemRoot() {
130 return new PreferencesNode(Preferences.systemRoot());
131 }
132
133 /* (non-Javadoc)
134 * @see java.util.prefs.Preferences#userNodeForPackage(java.lang.Class)
135 */
136 public static Preferences userNodeForPackage(Class c) {
137 return new PreferencesNode(Preferences.userNodeForPackage(c));
138 }
139
140 /* (non-Javadoc)
141 * @see java.util.prefs.Preferences#userRoot()
142 */
143 public static Preferences userRoot() {
144 return new PreferencesNode(Preferences.userRoot());
145 }
146
147 /***
148 * @return
149 */
150 public String absolutePath() {
151 return moPref.absolutePath();
152 }
153
154 /***
155 * @param ncl
156 */
157 public void addNodeChangeListener(NodeChangeListener ncl) {
158 moPref.addNodeChangeListener(ncl);
159 }
160
161 /***
162 * @param pcl
163 */
164 public void addPreferenceChangeListener(PreferenceChangeListener pcl) {
165 moPref.addPreferenceChangeListener(pcl);
166 }
167
168 /***
169 * @return
170 * @throws java.util.prefs.BackingStoreException
171 */
172 public String[] childrenNames() throws BackingStoreException {
173 return moPref.childrenNames();
174 }
175
176 /***
177 * @throws java.util.prefs.BackingStoreException
178 */
179 public void clear() throws BackingStoreException {
180 moPref.clear();
181 }
182
183 /***
184 * @param os
185 * @throws java.io.IOException
186 * @throws java.util.prefs.BackingStoreException
187 */
188 public void exportNode(OutputStream os)
189 throws IOException, BackingStoreException {
190 moPref.exportNode(os);
191 }
192
193 /***
194 * @param os
195 * @throws java.io.IOException
196 * @throws java.util.prefs.BackingStoreException
197 */
198 public void exportSubtree(OutputStream os)
199 throws IOException, BackingStoreException {
200 moPref.exportSubtree(os);
201 }
202
203 /***
204 * @throws java.util.prefs.BackingStoreException
205 */
206 public void flush() throws BackingStoreException {
207 moPref.flush();
208 }
209
210 /***
211 * @param key
212 * @param def
213 * @return
214 */
215 public String get(String key, String def) {
216 return moPref.get(key, def);
217 }
218
219 /***
220 * @param key
221 * @param def
222 * @return
223 */
224 public boolean getBoolean(String key, boolean def) {
225 return moPref.getBoolean(key, def);
226 }
227
228 /***
229 * @param key
230 * @param def
231 * @return
232 */
233 public byte[] getByteArray(String key, byte[] def) {
234 return moPref.getByteArray(key, def);
235 }
236
237 /***
238 * @param key
239 * @param def
240 * @return
241 */
242 public double getDouble(String key, double def) {
243 return moPref.getDouble(key, def);
244 }
245
246 /***
247 * @param key
248 * @param def
249 * @return
250 */
251 public float getFloat(String key, float def) {
252 return moPref.getFloat(key, def);
253 }
254
255 /***
256 * @param key
257 * @param def
258 * @return
259 */
260 public int getInt(String key, int def) {
261 return moPref.getInt(key, def);
262 }
263
264 /***
265 * @param key
266 * @param def
267 * @return
268 */
269 public long getLong(String key, long def) {
270 return moPref.getLong(key, def);
271 }
272
273 /* (non-Javadoc)
274 * @see java.lang.Object#hashCode()
275 */
276 public int hashCode() {
277 return moPref.hashCode();
278 }
279
280 /***
281 * @return
282 */
283 public boolean isUserNode() {
284 return moPref.isUserNode();
285 }
286
287 /***
288 * @return
289 * @throws java.util.prefs.BackingStoreException
290 */
291 public String[] keys() throws BackingStoreException {
292 return moPref.keys();
293 }
294
295 /***
296 * @return
297 */
298 public String name() {
299 return moPref.name();
300 }
301
302 /***
303 * @param pathName
304 * @return
305 */
306 public Preferences node(String pathName) {
307 return new PreferencesNode(moPref.node(pathName));
308 }
309
310 /***
311 * @param pathName
312 * @return
313 * @throws java.util.prefs.BackingStoreException
314 */
315 public boolean nodeExists(String pathName) throws BackingStoreException {
316 return moPref.nodeExists(pathName);
317 }
318
319 /***
320 * @param key
321 * @param value
322 */
323 public void put(String key, String value) {
324 moPref.put(key, value);
325 }
326
327 /***
328 * @param key
329 * @param value
330 */
331 public void putBoolean(String key, boolean value) {
332 moPref.putBoolean(key, value);
333 }
334
335 /***
336 * @param key
337 * @param value
338 */
339 public void putByteArray(String key, byte[] value) {
340 moPref.putByteArray(key, value);
341 }
342
343 /***
344 * @param key
345 * @param value
346 */
347 public void putDouble(String key, double value) {
348 moPref.putDouble(key, value);
349 }
350
351 /***
352 * @param key
353 * @param value
354 */
355 public void putFloat(String key, float value) {
356 moPref.putFloat(key, value);
357 }
358
359 /***
360 * @param key
361 * @param value
362 */
363 public void putInt(String key, int value) {
364 moPref.putInt(key, value);
365 }
366
367 /***
368 * @param key
369 * @param value
370 */
371 public void putLong(String key, long value) {
372 moPref.putLong(key, value);
373 }
374
375 /***
376 * @param key
377 */
378 public void remove(String key) {
379 moPref.remove(key);
380 }
381
382 /***
383 * @throws java.util.prefs.BackingStoreException
384 */
385 public void removeNode() throws BackingStoreException {
386 moPref.removeNode();
387 }
388
389 /***
390 * @param ncl
391 */
392 public void removeNodeChangeListener(NodeChangeListener ncl) {
393 moPref.removeNodeChangeListener(ncl);
394 }
395
396 /***
397 * @param pcl
398 */
399 public void removePreferenceChangeListener(PreferenceChangeListener pcl) {
400 moPref.removePreferenceChangeListener(pcl);
401 }
402
403 /***
404 * @throws java.util.prefs.BackingStoreException
405 */
406 public void sync() throws BackingStoreException {
407 moPref.sync();
408 }
409
410 }
This page was automatically generated by Maven